<template>
	<view>
		<view class="top">
			<view class="img_user">
				<u-upload ref="uUpload" :fileList="fileList1" :action="actions" name="1" multiple :maxCount="1"
					:auto-upload="false" @on-uploaded='Upload' @afterRead="afterRead" @delete="deletePic">
					<image :src="icon" class="img_user" mode="widthFix"></image>
				</u-upload>
			</view>
			<!-- <image src="../../static/image/head.jpg" class="img_user"></image>
			<view class="camera">
				<u-icon name="camera" color="#fff" size="22" ></u-icon>
			</view> -->
		</view>
		<view class="bottom">
			<u-cell-group>
				<u-cell icon="share" title="个人资料" :isLink="true" url="/pageUser/pages/my/my"></u-cell>
				<u-cell icon="map" title="用户管理" :isLink="true" url="/pageUser/pages/my/userlist"></u-cell>
				<u-cell icon="map" title="隐私协议" :isLink="true" url="/pageUser/pages/my/privacy"></u-cell>
				<u-cell icon="map" title="关于我们" :isLink="true" url="/pageUser/pages/my/about"></u-cell>
			</u-cell-group>
		</view>

	</view>
</template>


<script>
	import {
		updateUmsMember,
	} from '../../api/index.js'
	import env from '../../utils/env.js'
	export default {
		data() {
			return {
				fileList1: [],
				icon:'',
				actions: env.BASE_API + '/ftp/file/upload'
			}
		},
		created() {
			//#ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			//#endif
		},
		onLoad() {
			this.icon=uni.getStorageSync("photo")
		},
		methods: {
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: env.BASE_API + '/ftp/file/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			Upload() {
				this.$refs.uUpload.upload()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}

	.top {
		width: 100vh;
		height: 150px;
		background: linear-gradient(to bottom right, #eafefd, #fff);
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		padding-left: 20px;

		.img_user {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}

		.camera {
			position: relative;
			top: -20px;
			left: -20px;
		}
	}

	.bottom {
		height: calc(100vh - 150px);
		background-color: #fff;
	}
</style>